<?php
class SettingSaveSiteAction extends AdminAction
{
	public function __construct()
	{
		parent::__construct();
		$this->responseType = 'json';
	}
	
	protected function afterConstruct()
	{
		$this->parseDtds('site','setting');
	}
	
	public function execute()
	{
		$data = $this->getValidData();
		if($data['ipcheck']!=1)
		{
			$data['ipcheck'] = 0;
		}
		
		//logo
		$uploadResult = $this->upload('logo', $this->getUploadDir());
		if($uploadResult['code']==0)
		{
			$image = $this->getUploadUrl().$uploadResult['file'];
			$data['logo'] = $image;
		}
		else if($uploadResult['code']>1)
		{
			$this->data['error_messages']['logo'] = array('error'=>$uploadResult['message']);
		}
		
		if(empty($this->data['error_messages']))
		{
			Util::updateSetting(array('site'=>$data));
			
			$this->code = 200;
		}
		else
		{
			$this->code = 500;
		}
	}
}
